package com.revzone.demo001.mapper;

import com.revzone.demo001.entity.Upload;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.revzone.demo001.entity.UploadGroup;
import com.revzone.demo001.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author Admin
* @description 针对表【upload】的数据库操作Mapper
* @createDate 2025-07-01 16:05:29
* @Entity com.revzone.demo001.entity.Upload
*/
@Mapper
public interface UploadMapper extends BaseMapper<Upload> {

    // 带分页的分组查询
    @Select("<script>" +
            "SELECT pro_id, MIN(report_path) AS path, COUNT(*) AS total_records, MIN(create_time) AS create_time " +
            "FROM upload " +
            "GROUP BY pro_id "+"LIMIT #{pageSize} OFFSET #{offset}" +
            "</script>")
    List<UploadGroup> groupByProIdPage(@Param("pageSize") long pageSize, @Param("offset") long offset);
    // 带分页的分组查询
    @Select("<script>" +
            "SELECT pro_id, MIN(report_path) AS path, COUNT(*) AS total_records, MIN(create_time) AS create_time " +
            "FROM upload " +
            "WHERE upload.pro_id=#{pro_id}"+
            "GROUP BY pro_id "+"LIMIT #{pageSize} OFFSET #{offset}" +
            "</script>")
    List<UploadGroup> groupByProIdPageSearch(@Param("pageSize") long pageSize, @Param("offset") long offset, @Param("pro_id") String pro_id);
    // 带时间的分组查询
    @Select("<script>" +
            "SELECT pro_id, MIN(report_path) AS path, COUNT(*) AS total_records, MIN(create_time) AS create_time " +
            "FROM upload " +
            "WHERE upload.create_time &gt;#{startTime} and upload.create_time &lt;#{endTime} "+
            "GROUP BY pro_id "+"LIMIT #{pageSize} OFFSET #{offset}" +
            "</script>")
    List<UploadGroup> groupByProIdPageSearchTime(@Param("pageSize") long pageSize, @Param("offset") long offset, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
    // 分组总数查询
    @Select("<script>" +
            "SELECT COUNT(DISTINCT pro_id) " +
            "FROM upload " +
            "<where>" +
            "   <if test='proId != null and proId != \"\"'>" +
            "       AND pro_id = #{proId}" +
            "   </if>" +
            "</where>" +
            "</script>")
    Long countGroups(@Param("proId") String proId);
    @Select("<script>" +
            "SELECT   pro_id," +
            "  MIN(report_path) AS path," +
            "  COUNT(*) AS total_records" +
            "   FROM `upload` GROUP BY upload.pro_id" +
            "</script>")
    List<String> groupList();
    @Delete("<script>" +
            "DELETE FROM `upload` "+
            "<where>" +
            "   <if test='proId != null and proId != \"\"'>" +
            "       AND pro_id = #{proId}" +
            "   </if>" +
            "</where>" +
            "</script>")
    boolean deleteList(@Param("proId") String proId);

}




